﻿using System;

namespace YArchitech.MEP
{
	public struct HYTubeSize : IComparable
	{
		public HYTubeShape Shape
		{
			get
			{
				return this.m_Shape;
			}
			set
			{
				this.m_Shape = value;
			}
		}

		public string ShapeString
		{
			get
			{
				return HYTubeShapeDescription.ToString(this.Shape);
			}
		}

		public double Width
		{
			get
			{
				return this.width;
			}
			set
			{
				this.width = value;
			}
		}

		public double Height
		{
			get
			{
				if (this.m_Shape == HYTubeShape.Round)
				{
					return this.width;
				}
				return this.height;
			}
			set
			{
				this.height = value;
			}
		}

		public double Diameter
		{
			get
			{
				return this.width;
			}
			set
			{
				this.width = value;
			}
		}

		public double LongAxis
		{
			get
			{
				return this.width;
			}
			set
			{
				this.width = value;
			}
		}

		public double ShortAxis
		{
			get
			{
				return this.height;
			}
			set
			{
				this.height = value;
			}
		}

		public double Factor
		{
			get
			{
				if (this.m_Shape == HYTubeShape.Round)
				{
					return 1.0;
				}
				return this.width / this.height;
			}
		}

		public double Area
		{
			get
			{
				double num = HYMathUtility.Area_Round(this.width);
				HYTubeShape shape = this.Shape;
				if (shape != HYTubeShape.Rectangular)
				{
					if (shape == HYTubeShape.Oval)
					{
						num = HYMathUtility.Area_Oval(this.width, this.height);
					}
				}
				else
				{
					num = HYMathUtility.Area_Rectangular(this.width, this.height);
				}
				return num / 1000000.0;
			}
		}

		public double Circumference
		{
			get
			{
				double num = HYMathUtility.Circumference_Round(this.width);
				HYTubeShape shape = this.Shape;
				if (shape != HYTubeShape.Rectangular)
				{
					if (shape == HYTubeShape.Oval)
					{
						num = HYMathUtility.Circumference_Oval(this.width, this.height);
					}
				}
				else
				{
					num = HYMathUtility.Circumference_Rectangular(this.width, this.height);
				}
				return num / 1000.0;
			}
		}

		public double D
		{
			get
			{
				return 4.0 * this.Rs;
			}
		}

		public double Rs
		{
			get
			{
				return this.Area / this.Circumference;
			}
		}

		public bool IsValid
		{
			get
			{
				return this.Area > HYMathUtility.Area_Round(0.005);
			}
		}

		public double GetVelocity(double flow)
		{
			return Hydrokinetics.Velocity(flow, this.Area);
		}

		public HYTubeSize(HYTubeShape sp = HYTubeShape.Round, double w = 800.0, double h = 320.0)
		{
			this.m_Shape = sp;
			this.width = w;
			this.height = h;
		}

		public double CalVelocity(double flow)
		{
			double result;
			try
			{
				result = Hydrokinetics.Velocity(flow, this.Area);
			}
			catch
			{
				result = 0.0;
			}
			return result;
		}

		public int CompareTo(object obj)
		{
			if (this.Equals(obj))
			{
				return 0;
			}
			if (obj == null)
			{
				return 1;
			}
			int result;
			try
			{
				HYTubeSize b = (HYTubeSize)obj;
				if (this > b)
				{
					result = 1;
				}
				else
				{
					result = -1;
				}
			}
			catch
			{
				result = 1;
			}
			return result;
		}

		public override bool Equals(object obj)
		{
			if (obj == null)
			{
				return false;
			}
			bool result;
			try
			{
				result = (this == (HYTubeSize)obj);
			}
			catch
			{
				result = false;
			}
			return result;
		}

		public override int GetHashCode()
		{
			return base.GetHashCode();
		}

		public override string ToString()
		{
			return base.ToString();
		}

		public static bool operator >(HYTubeSize a, HYTubeSize b)
		{
			if (a.Shape != b.Shape)
			{
				return a.Shape > b.Shape;
			}
			if (a.Shape == HYTubeShape.Round)
			{
				return a.Diameter > b.Diameter;
			}
			if (HYMathUtility.IsEqual(a.Width, b.Width, 0.001))
			{
				return a.Height > b.Height;
			}
			return a.Width > b.Width;
		}

		public static bool operator <(HYTubeSize a, HYTubeSize b)
		{
			if (a.Shape != b.Shape)
			{
				return a.Shape < b.Shape;
			}
			if (a.Shape == HYTubeShape.Round)
			{
				return a.Diameter < b.Diameter;
			}
			if (HYMathUtility.IsEqual(a.Width, b.Width, 0.001))
			{
				return a.Height < b.Height;
			}
			return a.Width < b.Width;
		}

		public static bool operator ==(HYTubeSize a, HYTubeSize b)
		{
			return a.Shape == b.Shape && HYMathUtility.IsEqual(a.Diameter, b.Diameter, 0.001) && (a.Shape == HYTubeShape.Round || HYMathUtility.IsEqual(a.Height, b.Height, 0.001));
		}

		public static bool operator !=(HYTubeSize a, HYTubeSize b)
		{
			return !(a == b);
		}

		private HYTubeShape m_Shape;

		private double width;

		private double height;
	}
}
